using Fungus;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMove : MonoBehaviour
{
    public float walkspeed;
    public float roraraspeed;
    float Xmove;
    float Zmove;
    float rotationX;
    float rotationY;
   public  Rigidbody rb;
    public AudioSource audioSource;
    public AudioClip audioclip;
    // Start is called before the first frame update
    public Animator anim;
    void Start()
    {
        Cursor.lockState = CursorLockMode.Locked;
        Cursor.visible = true;
        rotationX = transform.localScale.x;
        rotationY = transform.localScale.y;
        anim = GetComponent<Animator>();
        audioSource = GetComponent<AudioSource>();
    }

    // Update is called once per frame
    void Update()
    {
        Vector3 force = new Vector3(0,3,0);
        Xmove = Input.GetAxis("Horizontal")* walkspeed *Time.deltaTime;
        Zmove = Input.GetAxis("Vertical") * walkspeed * Time.deltaTime;
        rotationX -= Input.GetAxis("Mouse Y") * roraraspeed;
        rotationY += Input.GetAxis("Mouse X") * roraraspeed;
        rotationX = Mathf.Clamp(rotationX,-15f,15f);
        if (Zmove != 0)
        {
            anim.SetBool("iswalking", true);
            
                
            
             
            
        }
        else
        {
            anim.SetBool("iswalking", false);
        }
        if (Input.GetKeyDown(KeyCode.Space))
        {
            rb.AddForce(force,ForceMode.Impulse);
        }
        Vector3 momement = new Vector3(Xmove, 0, Zmove);
        transform.Translate(momement);
        transform.localEulerAngles = new Vector3(rotationX, rotationY, 0);
        
    }
    private void FixedUpdate()
    {
       
    }
    
}
